/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package a;

import camada.bancodedados.conexao.Conexao;
import combomodel.auxiliar.ComboBoxMunicipioModel;
import eloma.classe.Cliente;
import eloma.classe.auxiliar.Municipio;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
import java.util.logging.Level;
import javax.swing.JOptionPane;
import javax.swing.border.Border;
import org.jdesktop.swingx.error.ErrorInfo;
import relatorio.clientes.ReportCliente;
import utilitarios.Exceptions;
import utilitarios.erros.MessagemErro;

/**
 *
 * @author Ícaro
 */
public class internalFrmCadCliente extends javax.swing.JInternalFrame {

    private static Connection con;
    Border border;
    Exceptions exceptions = new Exceptions();

    boolean editar = false;

    /**
     * Creates new form internalFrmCadCliente
     */
    public internalFrmCadCliente() {
        initComponents();
        carregarCombo();
        capturaClientes();
        //border = txtNome.getBorder();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jScrollPane1 = new javax.swing.JScrollPane();
        jPanel1 = new javax.swing.JPanel();
        jToolBar1 = new javax.swing.JToolBar();
        btNaoSeiAinda = new org.jdesktop.swingx.JXHyperlink();
        btNovo = new org.jdesktop.swingx.JXHyperlink();
        btSalvar = new org.jdesktop.swingx.JXHyperlink();
        btEditar = new org.jdesktop.swingx.JXHyperlink();
        btExcluir = new org.jdesktop.swingx.JXHyperlink();
        btCancelar = new org.jdesktop.swingx.JXHyperlink();
        jSeparator1 = new javax.swing.JToolBar.Separator();
        btPrimeiro = new org.jdesktop.swingx.JXHyperlink();
        btAnterior = new org.jdesktop.swingx.JXHyperlink();
        btProximo = new org.jdesktop.swingx.JXHyperlink();
        btUltimo = new org.jdesktop.swingx.JXHyperlink();
        jSeparator2 = new javax.swing.JToolBar.Separator();
        jXHyperlink11 = new org.jdesktop.swingx.JXHyperlink();
        jXHyperlink12 = new org.jdesktop.swingx.JXHyperlink();
        jSeparator5 = new javax.swing.JToolBar.Separator();
        txtSair = new org.jdesktop.swingx.JXHyperlink();
        jSeparator4 = new javax.swing.JSeparator();

        setTitle("Cadastro Cliente");
        setToolTipText("Cadastro Cliente");

        jScrollPane1.setBorder(null);

        jPanel1.setToolTipText("Cadastro Cliente");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 1138, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 550, Short.MAX_VALUE)
        );

        jScrollPane1.setViewportView(jPanel1);

        jToolBar1.setFloatable(false);
        jToolBar1.setToolTipText("Cadastro Cliente");

        btNaoSeiAinda.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/internal/cad/document.png"))); // NOI18N
        btNaoSeiAinda.setText("");
        btNaoSeiAinda.setEnabled(false);
        btNaoSeiAinda.setFocusable(false);
        btNaoSeiAinda.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btNaoSeiAinda.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(btNaoSeiAinda);

        btNovo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/internal/cad/document_add.png"))); // NOI18N
        btNovo.setText("");
        btNovo.setFocusable(false);
        btNovo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btNovo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btNovo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btNovoActionPerformed(evt);
            }
        });
        jToolBar1.add(btNovo);

        btSalvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/internal/cad/document_ok.png"))); // NOI18N
        btSalvar.setText("");
        btSalvar.setEnabled(false);
        btSalvar.setFocusable(false);
        btSalvar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btSalvar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btSalvarActionPerformed(evt);
            }
        });
        jToolBar1.add(btSalvar);

        btEditar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/internal/cad/document_edit.png"))); // NOI18N
        btEditar.setText("");
        btEditar.setFocusable(false);
        btEditar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btEditar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btEditar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btEditarActionPerformed(evt);
            }
        });
        jToolBar1.add(btEditar);

        btExcluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/internal/cad/document_error.png"))); // NOI18N
        btExcluir.setText("");
        btExcluir.setFocusable(false);
        btExcluir.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btExcluir.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btExcluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btExcluirActionPerformed(evt);
            }
        });
        jToolBar1.add(btExcluir);

        btCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/internal/cad/document_delete.png"))); // NOI18N
        btCancelar.setText("");
        btCancelar.setEnabled(false);
        btCancelar.setFocusable(false);
        btCancelar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btCancelar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btCancelarActionPerformed(evt);
            }
        });
        jToolBar1.add(btCancelar);
        jToolBar1.add(jSeparator1);

        btPrimeiro.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/internal/move/media_rewind.png"))); // NOI18N
        btPrimeiro.setText("");
        btPrimeiro.setFocusable(false);
        btPrimeiro.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btPrimeiro.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btPrimeiro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btPrimeiroActionPerformed(evt);
            }
        });
        jToolBar1.add(btPrimeiro);

        btAnterior.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/internal/move/media_step_back.png"))); // NOI18N
        btAnterior.setText("");
        btAnterior.setFocusable(false);
        btAnterior.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btAnterior.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btAnterior.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btAnteriorActionPerformed(evt);
            }
        });
        jToolBar1.add(btAnterior);

        btProximo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/internal/move/media_step_forward.png"))); // NOI18N
        btProximo.setText("");
        btProximo.setFocusable(false);
        btProximo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btProximo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btProximo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btProximoActionPerformed(evt);
            }
        });
        jToolBar1.add(btProximo);

        btUltimo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/internal/move/media_fast_forward.png"))); // NOI18N
        btUltimo.setText("");
        btUltimo.setFocusable(false);
        btUltimo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btUltimo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btUltimo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btUltimoActionPerformed(evt);
            }
        });
        jToolBar1.add(btUltimo);
        jToolBar1.add(jSeparator2);

        jXHyperlink11.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/internal/print/document_view.png"))); // NOI18N
        jXHyperlink11.setText("");
        jXHyperlink11.setFocusable(false);
        jXHyperlink11.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jXHyperlink11.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jXHyperlink11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jXHyperlink11ActionPerformed(evt);
            }
        });
        jToolBar1.add(jXHyperlink11);

        jXHyperlink12.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/internal/print/printer.png"))); // NOI18N
        jXHyperlink12.setText("");
        jXHyperlink12.setFocusable(false);
        jXHyperlink12.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jXHyperlink12.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jXHyperlink12.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jXHyperlink12ActionPerformed(evt);
            }
        });
        jToolBar1.add(jXHyperlink12);
        jToolBar1.add(jSeparator5);

        txtSair.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/internal/move/window_delete.png"))); // NOI18N
        txtSair.setText("");
        txtSair.setFocusable(false);
        txtSair.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        txtSair.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        txtSair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtSairActionPerformed(evt);
            }
        });
        jToolBar1.add(txtSair);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jSeparator4))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator4, javax.swing.GroupLayout.PREFERRED_SIZE, 5, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void txtSairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtSairActionPerformed
        try {

            con = Conexao.getCon();
            con.rollback();

            this.setVisible(false);

        } catch (SQLException e) {
            MessagemErro erro = new MessagemErro(new ErrorInfo("Erro no Sistema", "Não é Possível Continuar, Sistema Inativo", null, "Fatal", e, Level.WARNING, null), 1);
        }
    }//GEN-LAST:event_txtSairActionPerformed

    private void btPrimeiroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btPrimeiroActionPerformed

    }//GEN-LAST:event_btPrimeiroActionPerformed

    private void btUltimoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btUltimoActionPerformed

    }//GEN-LAST:event_btUltimoActionPerformed

    private void btProximoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btProximoActionPerformed

    }//GEN-LAST:event_btProximoActionPerformed

    private void btAnteriorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btAnteriorActionPerformed

    }//GEN-LAST:event_btAnteriorActionPerformed

    private void jXHyperlink11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jXHyperlink11ActionPerformed

    }//GEN-LAST:event_jXHyperlink11ActionPerformed

    private void btNovoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btNovoActionPerformed

        habilitaBotao();
        habilitarTextFiel();
        limparTextField();

    }//GEN-LAST:event_btNovoActionPerformed

    private void btCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCancelarActionPerformed

        desabilitaBotao();
        desabilitarTextFiel();

        montarFieldsClientes(0);

    }//GEN-LAST:event_btCancelarActionPerformed

    private void btSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSalvarActionPerformed
        try {

        } catch (Exception e) {
            MessagemErro erro = new MessagemErro(new ErrorInfo("Erro no Sistema", "Não é Possível Continuar, Sistema Inativo", null, "Fatal", e, Level.WARNING, null), 1);
        }
    }//GEN-LAST:event_btSalvarActionPerformed

    private void jXHyperlink12ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jXHyperlink12ActionPerformed
        try {

        } catch (Exception e) {
            MessagemErro erro = new MessagemErro(new ErrorInfo("Erro no Sistema", "Não é Possível Continuar, Sistema Inativo", null, "Fatal", e, Level.WARNING, null), 1);
        }
    }//GEN-LAST:event_jXHyperlink12ActionPerformed

    private void btEditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btEditarActionPerformed
        try {

        } catch (Exception e) {
            MessagemErro erro = new MessagemErro(new ErrorInfo("Erro no Sistema", "Não é Possível Continuar, Sistema Inativo", null, "Fatal", e, Level.WARNING, null), 1);
        }
    }//GEN-LAST:event_btEditarActionPerformed

    private void btExcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btExcluirActionPerformed
        try {

            Object[] options = {"Confirmar", "Cancelar"};

            int i = JOptionPane.showOptionDialog(null,
                    "Excluir Cliente?", "Excluir Cliente",
                    JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null,
                    options, options[0]);

            if (i == JOptionPane.YES_OPTION) {

                try {

                    Object[] options2 = {"Confirmar", "Cancelar"};

                    int j = JOptionPane.showOptionDialog(null,
                            "Você Tem Certeza que Quer Excluir esse Cliente?", "Excluir?",
                            JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null,
                            options2, options[0]);

                    if (j == JOptionPane.YES_OPTION) {

                    }

                } catch (Exception e) {
                    MessagemErro erro = new MessagemErro(new ErrorInfo("Erro no Sistema", "Não é Possível Continuar, Sistema Inativo", null, "Fatal", e, Level.WARNING, null), 1);
                }

            }

        } catch (Exception e) {
            MessagemErro erro = new MessagemErro(new ErrorInfo("Erro no Sistema", "Não é Possível Continuar, Sistema Inativo", null, "Fatal", e, Level.WARNING, null), 1);
        }
    }//GEN-LAST:event_btExcluirActionPerformed

    private void capturaClientes() {
        try {

        } catch (Exception e) {
            MessagemErro erro = new MessagemErro(new ErrorInfo("Erro no Sistema", "Não é Possível Continuar, Sistema Inativo", null, "Fatal", e, Level.WARNING, null), 1);
        }
    }

    private void montarFieldsClientes(int index) {
        try {

        } catch (Exception e) {
            MessagemErro erro = new MessagemErro(new ErrorInfo("Erro no Sistema", "Não é Possível Continuar, Sistema Inativo", null, "Fatal", e, Level.WARNING, null), 1);
        }
    }

    private void habilitaBotao() {

        btNaoSeiAinda.setEnabled(false);
        btNovo.setEnabled(false);
        btSalvar.setEnabled(true);
        btEditar.setEnabled(false);
        btExcluir.setEnabled(false);
        btCancelar.setEnabled(true);

        btPrimeiro.setEnabled(false);
        btProximo.setEnabled(false);
        btUltimo.setEnabled(false);
        btAnterior.setEnabled(false);

    }

    private void desabilitaBotao() {

        btNaoSeiAinda.setEnabled(true);
        btNovo.setEnabled(true);
        btSalvar.setEnabled(false);
        btEditar.setEnabled(true);
        btExcluir.setEnabled(true);
        btCancelar.setEnabled(false);

        btPrimeiro.setEnabled(true);
        btProximo.setEnabled(true);
        btUltimo.setEnabled(true);
        btAnterior.setEnabled(true);
    }

    private void habilitarTextFiel() {
    }

    private void desabilitarTextFiel() {
    }

    private void limparTextField() {

    }

    private boolean validarTextField() {

        return false;

    }

    private void carregarCombo() {
        try {

        } catch (Exception e) {
            MessagemErro erro = new MessagemErro(new ErrorInfo("Erro no Sistema", "Não é Possível Continuar, Sistema Inativo", null, "Fatal", e, Level.WARNING, null), 1);
        }
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private org.jdesktop.swingx.JXHyperlink btAnterior;
    private org.jdesktop.swingx.JXHyperlink btCancelar;
    private org.jdesktop.swingx.JXHyperlink btEditar;
    private org.jdesktop.swingx.JXHyperlink btExcluir;
    private org.jdesktop.swingx.JXHyperlink btNaoSeiAinda;
    private org.jdesktop.swingx.JXHyperlink btNovo;
    private org.jdesktop.swingx.JXHyperlink btPrimeiro;
    private org.jdesktop.swingx.JXHyperlink btProximo;
    private org.jdesktop.swingx.JXHyperlink btSalvar;
    private org.jdesktop.swingx.JXHyperlink btUltimo;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JToolBar.Separator jSeparator1;
    private javax.swing.JToolBar.Separator jSeparator2;
    private javax.swing.JSeparator jSeparator4;
    private javax.swing.JToolBar.Separator jSeparator5;
    private javax.swing.JToolBar jToolBar1;
    private org.jdesktop.swingx.JXHyperlink jXHyperlink11;
    private org.jdesktop.swingx.JXHyperlink jXHyperlink12;
    private org.jdesktop.swingx.JXHyperlink txtSair;
    // End of variables declaration//GEN-END:variables

}
